<template>
  <div id="addfriend">  

     <el-form ref="form"  label-width="80px">           
          <el-row>
            <el-col :span="12" >  
                <div style="height:38px;line-height:38px;width:150px;"> 
                  <i class="el-icon-back" @click="goBack"></i> 
                  {{ $route.query.name }} 
                </div> 
            </el-col>
          </el-row>
    </el-form>

     <el-row>
        <el-col :span="24" style="text-align: right;">         
            <el-button type="primary" class="custom_color_button" style="margin-bottom:10px;" @click="mtk1_but()">添加好友</el-button>         
        </el-col>
  </el-row>

   <!-- 渲染数据list -->
   <add-friend-list :datalist="datalist"  @up_list_fun="list_fun"> </add-friend-list>

      
   <div style="margin-top:20px;text-align: center;">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :page-size="10"  
        layout="prev, pager, next, jumper"
        :total="count">
      </el-pagination>
    </div>


       <!-- 发放奖励 -->
    <el-dialog title="发放奖励" :visible.sync="mtk1"  width="450px">
        <div style="width:100%;"> 
          <el-form ref="form"   label-width="70px" style="width:100%;">
    
             <el-form-item label="姓名">
                    <el-input    v-model="mtk1_form.nickname" placeholder="姓名"></el-input>
              </el-form-item> 
               <el-form-item label="注册时间" style="width:100%;">
                 <el-date-picker type="date" placeholder="注册时间" format="yyyy-MM-dd" value-format="yyyy-MM-dd"  v-model="mtk1_form.register_time"  style="width:100%;"></el-date-picker>
            </el-form-item> 
              <el-form-item label="好友总数">
                    <el-input    v-model="mtk1_form.child_count" placeholder="好友总数"></el-input>
              </el-form-item> 
               <el-form-item label="累积获得">
                    <el-input    v-model="mtk1_form.ghy" placeholder="累积获得"></el-input>
              </el-form-item> 

               <el-row style="width:100%;">
                     <el-col :span="12">
                        <el-form-item label="头像">
                            <el-upload 
                                  action="uploadUrl"  
                                  :show-file-list="false"   
                                  :before-upload="beforeupload"
                                  :http-request="ImgUploadSectionFile">
                                  <div class="avatar-uploader">
                                      <img v-if="pic_form.head_img"  :src="pic_form.head_img" class="avatar">
                                      <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                  </div>
                            </el-upload>
                         </el-form-item>       
                     </el-col> 

                </el-row>                          
            </el-form>

            <div style="text-align: center;width:50%;margin:auto;">
                <el-button type="primary" class="custom_color_button" style="width:80%;" @click="mtk1_qr_but()">确认</el-button>
            </div>
        </div> 
    </el-dialog>       
  </div>
</template>

<script>
import AddFriendList from '@/view/Marketing/AddFriendList'
export default {
  name: 'addfriend',
  data () {
    return {
        datalist:[],
        page:1,
        count:0,
        mkid:'',
        mtk1:false,
        mtk1_form:{
            nickname:'',
            register_time:'',
            child_count:'',
            ghy:'',
        },
         pic_form:{
           head_img:'',
           upfile:'',
        },
    }
  },
 components:{
    AddFriendList
  },
  created(){
       
       this.mkid  = this.$route.query.mkid
       this.list_fun()
  },
  mounted (){
    
  },
  methods: {
     list_fun(){
        this.post("/marketer/listOfFriendLog", {
            mkid:this.mkid,
            page:this.page
        }).then(res => {  
            console.log(res)
            this.count = res.result.count
            this.datalist = res.result.list

            for(let item of this.datalist) {              
                item.tx_picture = [this.urlimg + item.head_img]                     
            }

        })
     },
     mtk1_but(){
       this.mtk1 = true
     },
     mtk1_qr_but(){
          this.post("/marketer/addFriendLog", {
               mkid:this.mkid,
               nickname:this.mtk1_form.nickname,
               register_time:this.mtk1_form.register_time,
               child_count:this.mtk1_form.child_count,
               ghy:this.mtk1_form.ghy,
               head_img:this.pic_form.upfile,
	        }).then(res => {
                //console.log(res)
             if(res.error_code == 0){
                        this.open1(res.result,'success')  
                        this.mtk1 = false
                        this.list_fun()
                }else {
                      this.open1(res.message,'warning') 
                }

         })
     },
     beforeupload(file){   //重新写入上穿 需要点击确认上传与表单一起提交
           if(this.upimglx(file) == false){  //判断是否为fales
              this.upimglxtitle()  //执行弹出错误             
              return false
            }  
            var windowURL = window.URL || window.webkitURL;               
            this.pic_form.head_img=windowURL.createObjectURL(file);             
            
            this.upimgpost("/image/uploadMultiple",file).then(res => {
              console.log(res.result.url )
               this.pic_form.upfile = res.result.url    
            })

            return false;
     },
     ImgUploadSectionFile(param){//图片上传    
      },
     goBack() {
        this.$router.go(-1)
    },
     handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.page = val
        this.list_fun()
        console.log(`当前页: ${val}`);
      }
  }
}
</script>


<style scoped>
.avatar-uploader  {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 150px;
    height: 150px;
    line-height: 150px;
    text-align: center;
  }
  .avatar {
    width: 150px;
    height: 150px;
    display: block;
  }
</style>
